#! /bin/sh /usr/share/dpatch/dpatch-run
## 05_distinguish-URL-spans-over-many-rows.dpatch by Liu Yubao <yubao.liu@gmail.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: distinguish URL spans over many rows

@DPATCH@
diff -urNad qterm~/qterm/qtermbbs.cpp qterm/qterm/qtermbbs.cpp
--- qterm~/qterm/qtermbbs.cpp	2006-07-10 15:36:13.000000000 +0800
+++ qterm/qterm/qtermbbs.cpp	2007-10-10 05:57:32.000000000 +0800
@@ -322,8 +322,10 @@
 	if (!checkIP) //don't update when we only need ip
 		m_rcUrl = QRect(0,0,0,0);
 
-	QCString cstrText = m_pBuffer->at(m_ptCursor.y())->getText();
-
+	QTermTextLine* textLine = m_pBuffer->at(m_ptCursor.y());
+	if (NULL == textLine)
+		return false;
+	QCString cstrText = textLine->getText();
 
 	if(at>=cstrText.length())
 		return false;
@@ -464,6 +466,29 @@
 		}else
 			m_cstrUrl = "http://"+m_cstrUrl;
 	
+	// fix up m_cstrUrl for URL spans over many rows.
+	// NOTE: I don't fix up m_rcUrl, so the URL is only distinguished
+	// when the cursor lies on the first line of this URL.
+	if (end == cstrText.length()) {
+		int row = m_ptCursor.y();
+		do {
+			textLine = m_pBuffer->at(++row);
+			if (NULL == textLine)
+				break;
+
+			cstrText = textLine->getText();
+
+			for (i = 0; i < cstrText.length() &&
+					!isIllURLChar(cstrText.at(i)); i++)
+				;
+			if (i > 0)
+				m_cstrUrl += cstrText.mid(0, i);
+			// we reach the end of this long URL
+			if (i < cstrText.length())
+				break;
+		} while (1);
+	}
+
 	rcUrl = QRect(url, m_ptCursor.y(), end-url, 1);
 	if (!checkIP) // don't update when we only need ip
 		m_rcUrl = rcUrl;
